/**
 * Created by zhoua on 2016/12/18.
 */


var _interface = require('../../models/scjg/scjg');
var _institutional = require('../../models/institutional/institutional');
// 最近三十天与今年 格式：new Date() to 2012-03-21
function dateToGs(type) {
    var d       = new Date();
    // 当前日期
    var month   = d.getMonth() + 1 > 9 ? (d.getMonth() + 1 ) : '0' + (d.getMonth() + 1);
    var day     = d.getDate() > 9 ? d.getDate() : '0' + d.getDate();
    var endDate = d.getFullYear() + '-' + month + '-' + day;

    // 三十天前日期
    var bDi       = d.setDate(d.getDate() - 30);
    var bD        = new Date(bDi);
    var bMonth    = bD.getMonth() + 1 > 9 ? (bD.getMonth() + 1 ) : '0' + (bD.getMonth() + 1);
    var bDay      = bD.getDate() > 9 ? bD.getDate() : '0' + bD.getDate();
    var beginDate = bD.getFullYear() + '-' + bMonth + '-' + bDay;

    if (type == 'month') {
        var time = {
            beginDate: beginDate,
            endDate  : endDate
        }
    }

    if (type == 'year') {
        var time = {
            beginDate: d.getFullYear() + '-01-01',
            endDate  : endDate
        }
    }

    if (type == '') {
        var time = {
            beginDate: '',
            endDate  : ''
        }
    }

    return time;
}
exports.abnormal = function (req, res) {
    var type1 = req.body.type;
    if (type1 == 'oths') {
        var beginDate = req.body.beginDate || '',
            endDate   = req.body.endDate || '';
    } else {
        var beginDate = dateToGs(type1).beginDate || '',
            endDate   = dateToGs(type1).endDate || '';
    }
    _interface.getExceptionDir({
        regNum:req.body.regNum||"",
        beginDate:beginDate,
        endDate:endDate,
        pageRowNum:req.body.pageRowNum||"",
        pageIndex:req.body.pageIndex||"",
        custNameLike:req.body.custNameLike||""
    }).done(function(data){
        res.send(JSON.parse(data));
    })
};
exports.custCheckPublic = function (req, res) {
    var type1 = req.body.type;
    if (type1 == 'oths') {
        var beginDate = req.body.beginDate || '',
            endDate   = req.body.endDate || '';
    } else {
        var beginDate = dateToGs(type1).beginDate || '',
            endDate   = dateToGs(type1).endDate || '';
    }
    _interface.getCustCheck({
        regNum:req.body.regNum||"",
        beginDate:beginDate||"",
        endDate:endDate||"",
        pageRowNum:req.body.pageRowNum||"",
        custNameLike:req.body.custNameLike||"",
        pageIndex:req.body.pageIndex||""
    }).done(function(data){
        console.log(data);
        res.send(JSON.parse(data));
    })
};
exports.Punish = function (req, res) {
    _interface.getPunish({
        regNum:req.body.regNum||"",
        beginDate:req.body.beginDate||"",
        endDate:req.body.endDate||"",
        pageRowNum:req.body.pageRowNum||"",
        pageIndex:req.body.pageIndex||"",
        custName :req.body.custName||"",
        custNameLike :req.body.custNameLike||""
    }).done(function(data){
        res.send(JSON.parse(data));
    })
};


exports.exceptionDir = function (req, res) {
    var type = req.body.type;
    if (type == 'oths') {
        var beginDate = req.body.beginDate || '',
            endDate   = req.body.endDate || '';
    } else {
        var beginDate = dateToGs(type).beginDate || '',
            endDate   = dateToGs(type).endDate || '';
    }
    // console.log(2234);
    _interface.getExceptionDir({
        regNum:req.body.regNum||"",
        beginDate:beginDate,
        endDate:endDate,
        pageRowNum:req.body.pageRowNum||"",
        custName:req.body.custName||"",
        pageIndex:req.body.pageIndex||""
    }).done(function(data){
        // console.log('data ===================='+data);
        res.send(JSON.parse(data));
    })
};
//商事主体信息
exports.businessInformation = function (req, res) {
    _institutional.getBusinessInformation({
        custId: req.body.custId || "",
        regNum: req.body.regNum || "",
        custName: req.body.custName || ""

    }).done(function (data) {
        res.send(JSON.parse(data));
    })
};
//股东信息
exports.shareholder = function (req, res) {
    _institutional.getShareholder({
        regNum: req.body.regNum || ""
    }).done(function (data) {
        res.send(JSON.parse(data));
    })
};
//组织机构
exports.ganization = function (req, res) {
    _institutional.getGanization({
        regNum: req.body.regNum || ""
    }).done(function (data) {
        res.send(JSON.parse(data));
    })
};
//清算组
exports.liquidation = function (req, res) {
    _institutional.getLiquidation({
        regNum: req.body.regNum || ""
    }).done(function (data) {
        res.send(JSON.parse(data));
    })
};
//许可信息
exports.license = function (req, res) {
    _institutional.getLicense({
        regNum: req.body.regNum || ""
    }).done(function (data) {
        res.send(JSON.parse(data));
    })
};


exports.annual = function (req, res) {
    _institutional.getAnnual({
        regNum: req.body.regNum || ""
    }).done(function (data) {
        res.send(JSON.parse(data));
    })
};
//审批信息
exports.permitpublic = function (req, res) {
    _institutional.permitpublic({
        regNum: req.body.regNum || ""
    }).done(function (data) {
        res.send(JSON.parse(data));
    })
};